package com.tucc.hello.leetcode.no1_400.no1_200.no21_40.no24;

import com.tucc.hello.leetcode.common.ListNode;

import java.util.List;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode head = ListNode.of(1, 2, 3, 4);
        ListNode newHead = solution.swapPairs(head);
        ListNode.print(newHead);
    }

    public ListNode swapPairs(ListNode head) {
        ListNode newHead = head;
        if(head == null || head.next == null) {
            return newHead;
        }
        else{
            newHead = head.next;
            head.next = swapPairs(newHead.next);
            newHead.next = head;
            return newHead;
        }
    }


}
